package com.buddy.sds.auth.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buddy.sds.auth.entity.SystemDict;
import com.buddy.sds.auth.mapper.ISystemDictItemMapper;
import com.buddy.sds.auth.mapper.ISystemDictMapper;
import com.buddy.sds.auth.mapper.result.SystemDictCascasdeResultHandler;
import com.buddy.sds.auth.service.ISystemDictItemService;
import com.buddy.sds.auth.service.ISystemDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SystemDictServiceImpl extends ServiceImpl<ISystemDictMapper, SystemDict> implements ISystemDictService {

    @Autowired
    private ISystemDictItemMapper dictItemMapper;


    @Override
    public void getDictCascadeList(Page page) {

        SystemDictCascasdeResultHandler resultHandler = new SystemDictCascasdeResultHandler(dictItemMapper);

        baseMapper.selecCascadetList(page,resultHandler);

        page.setRecords(resultHandler.getSystemDicts());
    }

    @Transactional
    @Override
    public void deleteCascade(String dictId) {

        SystemDict dict = baseMapper.selectById(dictId);

        if(dict != null){

            baseMapper.deleteById(dictId);

            dictItemMapper.deleteByDict(dictId);
        }

    }

    @Override
    public boolean exisitIdent(String ident) {

        return baseMapper.existByIdent(ident);
    }

}
